from Tkinter import *
import pygame, sys
import random
#from nesne import Ball
import time
from pygame.sprite import Sprite


def startGame(): 
	pygame.init()
	 
	pencere = pygame.display.set_mode((500,400))
	pencere.fill((255,255,255))

	map_sheet = pygame.image.load('image/map.bmp').convert() 
	shuttle  = Ball((250,200))

	grup = pygame.sprite.Group(shuttle)

	mapX = 0
	mapY = 0

	while True:
		
		for event in pygame.event.get():
			if event.type == pygame.QUIT:
				sys.exit()   
			elif event.type == pygame.KEYDOWN and event.dict['key'] == pygame.K_UP:
				mapY += -1
				print "1"
				KEYSTATE_FORWARD = True         
			elif event.type == pygame.KEYUP and event.dict['key'] == pygame.K_UP: 
				print "2"
				KEYSTATE_FORWARD = False         
			elif event.type == pygame.KEYDOWN and event.dict['key'] == pygame.K_DOWN:
				mapY += 1
				print "3"
				KEYSTATE_BACKWARD = True         
			elif event.type == pygame.KEYUP and event.dict['key'] == pygame.K_DOWN:
				print "4"
				KEYSTATE_BACKWARD = False         
			elif event.type == pygame.KEYDOWN and event.dict['key'] == pygame.K_LEFT:
				print "5"
				KEYSTATE_TURNLEFT = True         
			elif event.type == pygame.KEYUP and event.dict['key'] == pygame.K_LEFT:
				mapX += -1
				print "6"
				KEYSTATE_TURNLEFT = False         
			elif event.type == pygame.KEYDOWN and event.dict['key'] == pygame.K_RIGHT:
				print "7"
				KEYSTATE_TURNRIGHT = True         
			elif event.type == pygame.KEYUP and event.dict['key'] == pygame.K_RIGHT:
				mapX += 1
				print "8"
				KEYSTATE_TURNRIGHT = False        
			elif event.type == pygame.KEYDOWN and event.dict['key'] == pygame.K_SPACE:
				print "9"
				KEYSTATE_FIRE = True         
			elif event.type == pygame.KEYUP and event.dict['key'] == pygame.K_SPACE:
				print "10"
				KEYSTATE_FIRE = False     
			# remainder of game loop here...
		
		pencere.fill((255,255,255))

		#area = pygame.Rect(250, 200, 500 , 400) 
		#pencere.blit(Ball.image, (4,0), area) 
		
		for sprite in grup.sprites():			
			area = pygame.Rect(mapX * 50, mapY * 50, 1262, 678) 
			pencere.blit(map_sheet, (4,0), area) 
			pencere.blit(sprite.image, sprite.rect)  
			
		
		pygame.display.flip()


class Ball(Sprite):
    
    def __init__(self,konum):
        Sprite.__init__(self)
       
        self.image = pygame.image.load("image/ball.PNG")
        self.image.set_colorkey((255,255,255))
        self.rect =  self.image.get_rect()
        self.rect.x, self.rect.y = konum
        
        self.say = 0
        self.c = self.rect.y